Skip to content

txtpbfmt: move descriptor file loading into the fmt command - #196

Merged
copybara-service[bot] merged 1 commit into
protocolbuffers:masterfrom
mvdan:descriptor-in-cmd
Sep 16, 2026
Merged

copybara-service[bot] merged 1 commit into
protocolbuffers:masterfrom
mvdan:descriptor-in-cmd

Conversation

@mvdan

@mvdan mvdan commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

(see commit message)

Fixes #195.

Importing parser pulled in protodesc and descriptorpb via impl's use of
the descriptor package, costing about 3 MB of binary size even though the
loading only happens when SortFieldsByFieldNumber is set. The guard is a
runtime condition, so the linker cannot drop the descriptor runtime.

Config now carries an already-resolved RootMessageDescriptor rather than
a descriptor file path and message name, and cmd/txtpbfmt resolves the
-proto_descriptor and -message_full_name flags into one. impl keeps its
cheap protoreflect import and loses the expensive ones, and the library
no longer reads files on the caller's behalf.

A hello-world binary importing parser drops from 7,966,362 to 3,091,409
bytes.

Fixes protocolbuffers#195.
@kssilveira

Copy link
Copy Markdown
Member

Thanks, I'm fixing the internal users.

@copybara-service
copybara-service Bot merged commit 6e6d8eb into protocolbuffers:master Sep 16, 2026
8 checks passed
@mvdan

mvdan commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

Thanks very much!

mvdan added a commit to cue-lang/cue that referenced this pull request Sep 17, 2026
encoding/protobuf/textproto is our only txtpbfmt consumer, and it
parses and prints text protos without a schema. Even so we linked the
entire protobuf runtime, because txtpbfmt/impl imported
txtpbfmt/descriptor to load descriptor set files, which pulled in
protodesc, protoregistry, descriptorpb, prototext and the rest.

protocolbuffers/txtpbfmt#196 moved that
loading into txtpbfmt's own fmt command, leaving the library needing
just the protoreflect interfaces. Twenty-seven packages drop out of the
cmd/cue build, and a release build as internal/ci/goreleaser produces
it (CGO_ENABLED=0, -trimpath, -ldflags="-s -w") goes from 26,366,112 to
24,522,912 bytes, 1,843,200 fewer or -7.0%.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I80a2053d907654d8d7cd2e05948306311c0148f9
GitOrigin-RevId: 0dc732511f01b4dd5baf9b5b18cc70f684172256
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

parser pulls in protodesc/descriptorpb, costing ~3 MB of binary size for a feature most callers don't use

2 participants